|
|
|
|
|
|
|
To avoid losing work, you should save often when you are working with API routines. You should certainly save files just before you run a program, especially if you are testing a new API call. You can make this process easier by activating the Visual Basic development environment's autosave feature. |
|
|
|
|
|
|
|
|
To do this, select Options from the Tools menu. In the Options dialog box, select the Environment tab. In Visual Basic 6, look in the "When a program starts" frame. To save your work automatically each time you run a program, click the Save Changes option button. If you want to be prompted to save changes before running a program, click the Prompt To Save Changes option. Earlier versions of Visual Basic have similar options. |
|
|
|
|
|
|
|
|
There are four steps to using the API: |
|
|
|
|
|
|
|
|
1. Identify the routine you want to use. |
|
|
|
|
|
|
|
|
2. Define any data structures you need to pass to the routine using a Type statement. |
|
|
|
|
|
|
|
|
3. Declare the routine using a Declare statement. |
|
|
|
|
|
|
|
|
These steps are covered in the following sections. |
|
|
|
|
|
|
|
|
The MSDN help that comes with Visual Basic 6 includes help on API functions. Set the HTML help application's Active Subset to (Entire Collection). Then the help will list entries for API functions. |
|
|
|
|
|
|
|
|
Some older versions of Visual Basic come with the normal help file Win31wh.hlp. This file contains help about many API functions. Look for this file in the Visual Basic directory's Winapi subdirectory. |
|
|
|
|
|
|
|
|
Microsoft's Knowledge Base is another good source of information on API functions. It contains many articles explaining how to use API functions to perform tasks that are difficult or impossible using Visual Basic alone. You can search the Knowledge Base at Microsoft's Web site. |
|
|
|
|
|
|
|
|
You can also gather information on API functions from books on the API. Many of these books were written for C programmers; but with a little practice, you will be able to translate between C declarations and Visual Basic declarations. |
|
|
|
|
|
|
|
|
Many API routines take special data structures as parameters. You can use the GetObject function, for example, to fill in the fields that describe a bitmap in a BITMAP data structure. In C, this structure is defined as: |
|
|
|
|
|